package com.wesley.spring.conf;

import com.wesley.spring.entity.Car;
import com.wesley.spring.entity.Driver;
import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * CustomConfig
 *
 * @author WangPanYong
 * @since 2021/08/31 14:54
 */
//@Component
@Configuration
public class CustomConfig {

    /**
     * 会覆盖 @ComponentScan 扫描的同名Bean
     * 这里会覆盖 @Component("car") 标注的Car
     */
//    @Bean(value = "car", autowire = Autowire.BY_NAME)
    @Bean(value = "car")
    public Car car() {
        System.out.println(" ====> 构造一辆Car ");
        Car car = new Car("Mazda");
        car.setDriver(driver());
        return car;
    }

    @Bean
    public Driver driver() {
        return new Driver();
    }

}
